import java.net.DatagramPacket;
import java.net.DatagramSocket;


public class TestReceiver {
    public static void main(String[] args) {

        try {
            DatagramSocket datagramSocket = new DatagramSocket(8888);
            byte[] data = new byte[1024];
            DatagramPacket datagramPacket = new DatagramPacket(data,data.length);
            System.out.println("接受者正在等待数据中...");
            datagramSocket.receive(datagramPacket);
            int len = datagramPacket.getLength();
            String str = new String(data,0,len);
            System.out.println("接受者收到:"+str);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
